<template>
	<el-card class="layout-query">
		<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item prop="courseName">
				<el-input v-model="state.queryForm.courseName" placeholder="课程名称"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button icon="Search" type="primary" @click="getDataList()">查询</el-button>
			</el-form-item>
			<el-form-item>
				<el-button icon="RefreshRight" @click="reset(queryRef)">重置</el-button>
			</el-form-item>
		</el-form>
	</el-card>

	<el-card>
		<el-table v-loading="state.dataListLoading" :data="state.dataList" border class="layout-table"
			show-overflow-tooltip @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
			<sm-image-column prop="attachmentList" label="课程图片" header-align="center" align="center"></sm-image-column>
			<el-table-column prop="courseName" label="课程名称" header-align="center" align="center"></el-table-column>
			<el-table-column prop="startTime" label="课程开始时间" header-align="center" align="center"></el-table-column>
			<el-table-column prop="endTime" label="课程结束时间" header-align="center" align="center"></el-table-column>
			<el-table-column label="作业数" header-align="center" align="center">
				<template #default="scope">
					<el-text type="primary">{{ scope.row.taskNum ? scope.row.taskNum : 0 }}</el-text>	
				</template>
			</el-table-column>
			<el-table-column prop="desciption" label="课程描述" header-align="center" align="center"></el-table-column>
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button type="primary" link @click="pushStuTaskList(scope.row.id)">查看该课程作业</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination :current-page="state.page" :page-sizes="state.pageSizes" :page-size="state.limit"
			:total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"></el-pagination>
	</el-card>
</template>

<script setup lang="ts" name="SmStuCourseIndex">
import { onMounted, reactive, ref } from 'vue'
import { useCrud } from '@/hooks'
import {IHooksOptions} from '@/hooks/interface'
import SmImageColumn from '@/components/sm-image-column/index.vue'
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

const queryRef = ref()
const state: IHooksOptions = reactive({
	dataListUrl: 'sm/course/stu/page',
	deleteUrl: '',
	queryForm: {
		courseName: ''
	}
})
//   带着课程id跳转到作业列表页面
const pushStuTaskList = (id: string) => {
	router.push({
		path: '/smstu/task/index',
		query: {
			courseUserId: id
		}
	});
}

const {getDataList,sizeChangeHandle,currentChangeHandle,selectionChangeHandle,deleteHandle,reset} = useCrud(state)
</script>